﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">关键字:</label>
                            <div class="layui-input-inline">
                                <input type="text" id="txt_keyword" name="txt_keyword" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon">&#xe615;</i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container" id="toolbar">
                <button id="NF-add" authorize class="layui-btn  data-add-btn layui-hide" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</button>
                <button id="NF-edit" authorize class="layui-btn  layui-btn-warm data-edit-btn layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
                <button id="NF-delete" authorize class="layui-btn  layui-btn-danger data-delete-btn layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
                <button id="NF-details" authorize class="layui-btn  layui-btn-normal data-info-btn layui-hide" lay-event="details"> <i class="layui-icon">&#xe60b;</i>置为入库状态</button>
            </div>
        </script>
        @*<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>*@
        <table id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>
<script>

    layui.use(['jquery', 'form', 'table', 'common', 'tablePlug', 'treeTable', 'layer'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            table = layui.table,
            treeTable = layui.treeTable,
            common = layui.common;
        var entity;
        //var loading = layer.load(0, { shade: false });
        //权限控制(js是值传递)
        toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);
        common.rendertable({
            elem: '#currentTableId',
            url: '/FixedAssets/Assetsrecords/GetGridJson',
            sqlkey: 'F_Id',//数据库主键
            cols: [[
                { type: 'checkbox', fixed: 'left' },
                { field: 'F_Id', title: 'ID', sort: true, hide: true, hideAlways: true },
                //此处需修改
                { field: 'F_AssetNo', title: '资产编号', width: 150, sort: true },
                { field: 'F_HierarchyName', title: '主类', width: 100 },
                { field: 'F_EquipmentName', title: '子类', width: 100 },
                { field: 'F_Code', title: '代码', width: 100, sort: true },
                { field: 'F_Name', title: '名称', width: 100, sort: true },
                { field: 'F_GlobalStatus', title: '资产状态', width: 90, sort: true },
                { field: 'F_ChartNumber', title: '规格型号', width: 90 },
                { field: 'F_CreditNo', title: '凭证号', width: 80 },
                { field: 'F_InvoiceNo', title: '发票号', width: 80 },
                { field: 'F_Measure', title: '计量单位', width: 90 },
                { field: 'F_Price', title: '单价', width: 80, sort: true },
                { field: 'F_ValueType', title: '价值类型', width: 90 },
                { field: 'F_UseAge', title: '使用年限', width: 90, sort: true },
                { field: 'F_Purpose', title: '用途', width: 80 },
                { field: 'F_Access', title: '获取方式', width: 90 },
                { field: 'F_FinancialSource', title: '经费来源', width: 90 },
                { field: 'F_PurchaseForm', title: '采购形式', width: 90 },
                { field: 'F_BuyDate', title: '购置日期', width: 90, sort: true },
                { field: 'F_UseStatus', title: '使用状况', width: 50 },
                { field: 'F_Note', title: '备注', width: 80 },
            ]]
        });
         //监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
           // 执行搜索重载
            common.reloadtable({
                elem: 'currentTableId',
                curr: 1,
                where: { keyword: data.field.txt_keyword }
            });
            return false;
        });
        table.on('row(currentTableFilter)', function (obj) {
            obj.tr.addClass("layui-table-click").siblings().removeClass("layui-table-click");
            entity = obj;
        })
        //toolbar监听事件

        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'openAll') {
                opTable.openAll();
                layer.msg("展开全部 isOpenAll: " + opTable.isOpenAll());
            } else if (obj.event === 'closeAll') {
                opTable.closeAll();
                layer.msg("关闭全部 isOpenAll: " + opTable.isOpenAll())
            }

            if (obj.event === 'add') {  // 监听添加操作
                common.modalOpen({
                    title: "添加界面",
                    url: "/FixedAssets/Assetsrecords/Form",
                    width: "1050px",
                    height: "600px",
                });
            }
            else if (obj.event === 'delete') {
                if (entity == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.deleteForm({
                    url: "/FixedAssets/Assetsrecords/DeleteForm",
                    param: { keyValue: entity.data.F_Id },
                    success: function () {
                        common.reload('data-search-btn');
                        entity = null;
                    }
                });
            }
            else if (obj.event === 'edit') {
                if (entity == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "编辑界面",
                    url: "/FixedAssets/Assetsrecords/Form?keyValue=" + entity.data.F_Id,
                    width: "1050px",
                    height: "600px",
                });
            }
            else if (obj.event === 'details') {
                if (entity == null) {
                    common.modalMsg("未选中数据", "warning");
                    return false;
                }
                common.modalOpen({
                    title: "查看界面",
                    url: "/FixedAssets/Assetsrecords/Details?keyValue=" + entity.data.F_Id,
                    width: "500px",
                    height: "500px",
                    btn: []
                });
            }
            return false;
        });
    });
</script>
